package Helpers;

import java.util.ArrayList;

import Entities.Admin;
import Entities.Candidate;
import Entities.Panel;
import Entities.Voter;

public class ServerMethods {

	DBMethods dbm = new DBMethods();
	
	public String loginStudent(String inputuname,String inputpass)
	{
		Voter v = dbm.getStudent(inputuname, inputpass);
		if(v!=null)
			return v.getId() + "#" + v.getUsername() + "#" + v.getPassword() + "#" + v.getSemster() + "#" + v.getActivated()+"#"+v.getEmail();
		else
			return "";
	}
	
	public String loginAdmin(String inputuname,String inputpass)
	{
		Admin a = dbm.isAdminExists(inputuname, inputpass);
		if(a!=null)
			return a.getAid() + "#" + a.getUsername() + "#" + a.getPassword();
		else
			return null;
	}
	
	public String getCandidatesThatCanBeVoted(String semster,String vid)
	{
		int nofCandidates = dbm.getNoOfCandidatesThatCanBeVoted(semster,vid);
		ArrayList<Candidate> cds = dbm.getCandidatesThatCanBeVoted(semster,vid);
		if(nofCandidates != 0)
		{
			String s = nofCandidates +"#";
			for(int i=0;i<nofCandidates;i++)
			{
				s+=cds.get(i).getCandidateID() + "%" + cds.get(i).getPanelID() + "%" + cds.get(i).getName() + "%" + cds.get(i).getSemster() + "%" + cds.get(i).getAgenda()+"#";
			}
			return s;
		}
		else
		{
			return "";
		}
		
	}
	
	public String getPanels()
	{
		ArrayList<Panel> cds = dbm.getPanels();
		if(cds.size() != 0)
		{
			String s = cds.size() +"#";
			for(int i=0;i<cds.size();i++)
			{
				s+=cds.get(i).getPid() + "%" + cds.get(i).getCategory() +"#";
			}
			return s;
		}
		else
		{
			return "";
		}
		
	}
	
	public int insertVote(String vid,int cid)
	{
		return dbm.insertVote(vid,cid);
	}
	
	public int insertPanel(String category)
	{
		return dbm.insertPanel(category);
	}
	
}
